package es.mgil.whoWantsToBeAMillonaire.handlers;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.widget.Toast;
import es.mgil.whoWantsToBeAMillonaire.R;
import es.mgil.whoWantsToBeAMillonaire.activities.Settings;
import es.mgil.whoWantsToBeAMillonaire.runnables.GetAddressRunnable;

public class GetAddressHandler extends Handler {
	private Settings context;

	public GetAddressHandler(Context context) {
		this.context = (Settings) context;
	}

	@Override
	public void handleMessage(Message msg) {
		switch (msg.what) {
		case GetAddressRunnable.GET_ADDRESS_ERROR_COORDINATES:
			// coordinates should be indicated in settings
			Toast.makeText(context,
					R.string.settings_address_error_coordinates,
					Toast.LENGTH_LONG).show();
			break;
		case GetAddressRunnable.GET_ADDRESS_ERROR_CONNECTION:
			// an error occurred with the connection
			Toast.makeText(context, R.string.settings_address_error_connection,
					Toast.LENGTH_LONG).show();
			break;
		case GetAddressRunnable.GET_ADDRESS_OK:
			// set the address to the text view
			String address = (String) msg.obj;
			context.addressTextView.setText(address);
			break;
		case GetAddressRunnable.GET_ADDRESS_NO_ADDRESS:
			// no address available
			Toast.makeText(context, R.string.settings_address_no_address,
					Toast.LENGTH_LONG).show();
			break;
		default:
			break;
		}

		context.addressButton.setEnabled(true);
		context.locateButton.setEnabled(true);
	}
}